import request from '@/utils/request'
import {
  getToken
} from '@/utils/auth'

// 分页（商品级）
export function pagingWarehouseGoods(query) {
  return request({
    url: '/warehouse/warehouseGoods/paging',
    method: 'get',
    params: query
  })
}

// 分页（团长首页商品查询）
export function pagingHomePageWarehouseGoods(query) {
  return request({
    url: '/warehouse/warehouseGoods/pagingWarehouseGoods',
    method: 'get',
    params: query
  })
}

// 分页（商品sku级）
export function pagingWarehouseGoodsSku(query) {
  return request({
    url: '/warehouse/warehouseGoods/pagingSku',
    method: 'get',
    params: query
  })
}

// 单个商品仓库库存详情
export function pagingStockDetail(query) {
  return request({
    url: '/warehouse/warehouseGoods/pagingStockDetail',
    method: 'get',
    params: query
  })
}

// 获取仓库商品详情
export function getWarehouseGoods(warehouseGoodsId) {
  return request({
    url: '/warehouse/warehouseGoods/get',
    method: 'get',
    params: {
      warehouseGoodsId: warehouseGoodsId
    }
  })
}

// 添加仓库商品
export function addGoods(data) {
  return request({
    url: '/warehouse/warehouseGoods/addGoods',
    method: 'post',
    data: data
  })
}

// 移除仓库商品
export function doRemoveGoods(data) {
  return request({
    url: '/warehouse/warehouseGoods/doRemoveGoods',
    method: 'post',
    data: data
  })
}

// 更新仓库商品
export function update(data) {
  return request({
    url: '/warehouse/warehouseGoods/update',
    method: 'post',
    data: data
  })
}

// 同步奇门仓库商品
export function syncWarehouseGoodsList(params) {
  return request({
    url: '/warehouse/warehouseGoods/syncWarehouseGoodsList',
    method: 'post',
    params
  })
}

// 同步奇门仓库库存
export function syncWarehouseGoodsStockList(params) {
  return request({
    url: '/warehouse/warehouseGoods/syncWarehouseGoodsStockList',
    method: 'post',
    params
  })
}

// 导出仓库已授权商品
export function doExportWarehouseGoods(warehouseId) {
  const url = process.env.BASE_API + '/warehouse/warehouseGoods/doExportWarehouseGoods?warehouseId=' + warehouseId
  return url + '&accessToken=' + getToken()
}

/**
 * 门店仓库商品
 * zhengjl 2021年5月31日14:31:22
 * @param {Object} query
 */
export function pagingStoreWarehouseGoods(query) {
  return request({
    url: '/warehouse/warehouseGoods/pagingStoreWarehouseGoods',
    method: 'get',
    params: query
  })
}
/**
 * 统计门店仓库商品状态数量
 * @param {Object} query
 */
export function listCountStoreWarehouseGoodsStatusNum(query) {
  return request({
    url: '/warehouse/warehouseGoods/listCountStoreWarehouseGoodsStatusNum',
    method: 'get',
    params: query
  })
}

/**
 * 根据仓库商品ID更新仓库商品价格
 * @param {Object} params
 */
export function updateWarehouseGoodsSellPrice(params) {
  return request({
    url: '/warehouse/warehouseGoods/updateWarehouseGoodsSellPrice',
    method: 'get',
    params: params
  })
}

/**
 * 根据仓库商品ID更新仓库商品库存
 * @param {Object} params
 */
export function updateWarehouseGoodsStock(params) {
  return request({
    url: '/warehouse/warehouseGoods/updateWarehouseGoodsStock',
    method: 'get',
    params: params
  })
}

/**
 * 根据仓库商品ID更新仓库商品上下架状态
 * @param {Object} params
 */
export function updateWarehouseGoodsStatus(params) {
  return request({
    url: '/warehouse/warehouseGoods/updateWarehouseGoodsStatus',
    method: 'get',
    params: params
  })
}
/**
 * 根据仓库商品ID更新团长佣金比例 团购仓商品团长佣金比例,如果为0则默认读取中台商品设置的店长佣金比例
 * @param {Object} params
 */
export function updateWarehouseGoodsCommanderCommissionRate(params) {
  return request({
    url: '/warehouse/warehouseGoods/updateWarehouseGoodsCommanderCommissionRate',
    method: 'get',
    params: params
  })
}
/**
 * 统计团购仓库商品各商品状态商品数量
 * @param {Object} params
 */
export function listCountGroupBuyWarehouseGoodsStatusNum(params) {
  return request({
    url: '/warehouse/warehouseGoods/listCountGroupBuyWarehouseGoodsStatusNum',
    method: 'get',
    params: params
  })
}
// 根据对接系统，同步仓库库存
export function syncWarehouseGoodsStockByDockingSystem(warehouseId, goodsIds) {
  const data = {
    warehouseId: warehouseId,
    goodsIds: goodsIds
  }
  return request({
    url: '/warehouse/warehouseGoods/syncWarehouseGoodsStockByDockingSystem',
    method: 'post',
    data: data
  })
}
